<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>分类商品</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <style>
        .aui-searchbar {
            background-color: white;
            padding: 0 .75rem;
            margin-top: 0.75rem;
        }

        .aui-searchbar form {
            width: 80%
        }

        .aui-searchbar-input {
            border-radius: 1.4rem;
            background-color: #F2F2F2;
            color: #7D7D7D;
            margin: 0 0.5rem 0 0;
            height: 1.8rem;
            line-height: 1.8rem;
        }

        .aui-searchbar-input input {
            height: 1.8rem;
        }

        .aui-searchbar .aui-iconfont {
            color: #7D7D7D;
        }

        .searchbar {
            padding: .3rem .75rem;
            background: #01A6FF;
            color: white;
            border-radius: 1.4rem;
        }

        #shopping_cart {
            position: fixed;
            z-index: 99;
            background: rgba(0, 0, 0, .6);
            width: 3rem;
            right: .4rem;
            bottom: 10rem;
            color: white;
            text-align: center;
            border-radius: .3rem;
            padding: .3rem 0;
            font-size: .7rem;
        }

        #shopping_cart img {
            width: 50%;
            margin: 0 auto;
        }

        #shop_recommended .aui-card-list-header {
            display: -webkit-box !important;
            font-size: .75rem;
            margin-top: .5rem;
        }

        #shop_recommended .aui-grid [class*=aui-col-] {
            padding: .5rem 0
        }

        #shop_recommended .aui-card-list-header,
        #shop_recommended .aui-card-list-footer {
            padding: 0;
        }

        #shop_recommended .aui-info {
            width: 100%;
        }

        #shop_recommended [class*=aui-col-xs-]:nth-child(odd) {
            padding-right: .6rem;
        }

        #shop_recommended [class*=aui-col-xs-]:nth-child(even) {
            padding-left: .6rem;
        }

        #shop_recommended .aui-card-list {
            margin-bottom: 1rem;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 购物车图标 -->
        <div id="shopping_cart" @click="openWin('shopping_cart')">
            <img src="../../../image/icon/gouwuche.png" alt="">
            <div>购物车</div>
        </div>
        <div class="aui-searchbar" id="search">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <form action="javascript:search();">
                    <input type="search" placeholder="输入商品名称进行搜索" id="search-input">
                </form>
                <i class="aui-iconfont aui-icon-close"></i>
            </div>
            <div class="searchbar" onclick="search()">搜索</div>
        </div>
        <!-- 商品列表 -->
        <section class="aui-content-padded" id="shop_recommended">
            <div class="aui-row-padded">
                <div class="aui-col-xs-6" @click="openWin('commodity_details', {id: goods.id, mid: api.pageParam.shop_id})" v-for="goods in goodsList">
                    <div class="aui-card-list">
                        <div class="aui-card-list-content">
                            <img :src="goods.pic" />
                        </div>
                        <div class="aui-card-list-header aui-ellipsis-2">
                            {{goods.name}}
                        </div>
                        <div class="aui-card-list-footer">
                            <div class="aui-info">
                                <div class="aui-info-item aui-text-danger aui-font-size-18">
                                    ￥{{goods.price}}
                                </div>
                                <div class="aui-info-item">{{goods.buy}}人付款</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();

        vm.init();
    }
    var vm = new Vue({
        el: "#app",
        data: {
            goodsList: [],
            pages: 1,
            name: '',
        },
        methods: {
            init() {
                this.page();
                this.getGoodsData();
            },
            getGoodsData() {
                var self = this;
                _ajax(Config.api.MallGoods, {
                    cid: api.pageParam.cide,
                    mid: api.pageParam.shop_id,
                    pages: self.pages,
                    name: self.name
                }, function(res) {
                    if (res.code === 200) {
                        if (res.data.length === 0) {
                            self.pages = -1;
                        } else {
                            self.goodsList = self.goodsList.concat(res.data);
                        }
                    }
                });
            },
            page() {
                // 下拉刷新
                var self = this;
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();

                    self.pages = 1;
                    self.goodsList = [];
                    self.getGoodsData();
                });

                //上拉加载
                push_up(function() {
                    if (self.pages === -1) {
                        $toast('数据已加载完毕');
                    } else {
                        ++self.pages;
                        self.getGoodsData();
                    }
                });
            },
            openWin(name, param = {}) {
                var winInfo = {
                    commodity_details: {
                        name: 'commodity_details_win',
                        url: './commodity_details_win.html',
                        param: param
                    },
                    shopping_cart: {
                        name: 'shopping_cart_win',
                        url: './shopping_cart_win.html',
                        param: param
                    }
                };
                open_w(winInfo[name].name, winInfo[name].url, winInfo[name].param);
            }
        }
    });

    function search() {
        var cont = $('#search-input').val();
        vm.name = cont;
        vm.pages = 1;
        vm.goodsList = [];
        vm.getGoodsData();
    }
</script>

</html>
